package edu.upc.fib.lamsandroid.server.web.controller;

import edu.upc.fib.lamsandroid.server.api.response.lesson.GetByIdResponse;
import edu.upc.fib.lamsandroid.server.api.response.lesson.GetByOrganisationsResponse;
import edu.upc.fib.lamsandroid.server.manager.LessonManager;
import edu.upc.fib.lamsandroid.server.api.model.Organisation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LessonController {

    @Autowired
    LessonManager lessonManager;

    @RequestMapping(value = "/lesson/getByOrganisation", method = RequestMethod.POST)
    public @ResponseBody GetByOrganisationsResponse getByOrganisation(
            @RequestParam("idOrganisation") Long idOrganisation) {

        Organisation organisation = new Organisation();
        organisation.setExternalId(idOrganisation);

        return new GetByOrganisationsResponse(lessonManager.getByOrganisation(organisation));
    }


    @RequestMapping(value = "/lesson/getById", method = RequestMethod.POST)
    public @ResponseBody GetByIdResponse getById(
            @RequestParam("id") Long id) {

        return new GetByIdResponse(lessonManager.fetchById(id));
    }



}
